package com.aliyun.heiyu.powermaster.server.dao.impl;

import com.aliyun.heiyu.common.util.JdbcUtil;
import com.aliyun.heiyu.powermaster.server.dao.DeviceServerDao;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;

public class DeviceServerDaoImpl  implements DeviceServerDao {

    @Override
    public String selectServerType(String sn) {
        String sql = "select server_type from  Device_Server where  device_id = ? ";
        Object[] params = new Object[1];
        params[0] = sn;
        Map<String,String>  map = JdbcUtil.queryForMap(sql, params);
        if(map==null){
            return "";
        }
        if(StringUtils.isNotBlank(map.get("server_type"))){
            return map.get("server_type");
        }
        return "";
    }

    @Override
    public String selectForecastPowerUpperLimit(String deviceId) {
        String sql = "select forecast_power_upper_limit from  Device_Server where  device_id = ? ";
        Object[] params = new Object[1];
        params[0] = deviceId;
        Map<String,String>  map = JdbcUtil.queryForMap(sql, params);
        if(map==null){
            return "";
        }
        if(StringUtils.isNotBlank(map.get("forecast_power_upper_limit"))){
            return map.get("forecast_power_upper_limit");
        }
        return "";
    }
    /** 获取服务器ip  */
    @Override
    public String selectDeviceServerIP(String deviceId){
        String sql = "select oob_ip from  Device_Server where  device_id = ? ";
        Object[] params = new Object[1];
        params[0] = deviceId;
        Map<String,String>  map = JdbcUtil.queryForMap(sql, params);
        if(map==null){
            return "";
        }
        if(StringUtils.isNotBlank(map.get("oob_ip"))){
            return map.get("oob_ip");
        }
        return "";
    }
}
